<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
            时间：O(n)
            空间：O(1)
        */
        // 回溯
        var maxSubArray = function(s, t) {
            let slen = s.length
            let tlen = t.length
            if (slen === 0) return true
            if (tlen === 0) return false
            let count = 0
            const backtrack = (sIndex, tIndex) => {
                if (sIndex >= slen || tIndex >= tlen) return
                if (s[sIndex] === t[tIndex]) {
                    count++
                    backtrack(++sIndex, ++tIndex)
                } else {
                    backtrack(sIndex, ++tIndex)
                }
                return count === slen
            }
            let sIndex = 0;
            let tIndex = 0;
            return backtrack(sIndex, tIndex)
        };
        console.log(maxSubArray('abc', 'ahbgdc'));
    </script>
</body>

</html>